package eventplanner.ejb.adders;

import eventplanner.entities.*;
import eventplanner.validation.URL;
import eventplanner.validation.URLValidator;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.UserTransaction;

@RunWith(Arquillian.class)
public class GroupAdderIT {

	@Deployment
	public static Archive<?> createTestArchive() {
		return ShrinkWrap.create(WebArchive.class, "test.war")
				.addClasses(GroupAdder.class, Doelgroep.class, Feed.class, Event.class, Event_.class, Identifiable.class,
						URL.class, URLValidator.class, EventType.class)
						// enable JPA
				.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
						// enable CDI
				.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
						// Deploy our test datasource
				.addAsWebInfResource("test-ds.xml", "test-ds.xml");
	}

	@Inject
	private GroupAdder adder;

	@PersistenceContext
	private EntityManager em;

	@Inject
	private UserTransaction transaction;

	@Test
	public void testName() throws Exception {
//		transaction.begin();
//		em.joinTransaction();
//
//		String doelgroep = new Doelgroep("Doelgroep");
//		em.persist(doelgroep);
//		doelgroep = em.find(Doelgroep.class, doelgroep.getId());
//
//		Event event = new Event("Test event", "No description", new Date(), new Date(), null, "");
//		em.persist(event);
//		event = em.find(Event.class, event.getId());
//		event.setDoelgroep(doelgroep);
//
//		event = new Event("Test event2", "No description2", new Date(), new Date(), null, "");
//		em.persist(event);
//		event = em.find(Event.class, event.getId());
//		event.setDoelgroep(doelgroep);
//
//		List<Event> events = adder.getEventsWithTarget(new HashSet<>(Arrays.asList(doelgroep)));
//		assertEquals(2, events.size());
//
//		transaction.rollback();

	}
}
